package com.google.code.timetrail.backend;

import java.util.Random;

public class DamagedShipEvent extends Event{
    /**
	 * 
	 */
	private static final long serialVersionUID = 5010L;
	private Item randomShipItem;
    public DamagedShipEvent(Control gameControl){
        
        Random rand = new Random();
        randomShipItem = gameControl.getInv().getRandomShipItem();
        int count = 0;
        while(randomShipItem.getCurrentAmount() <= 0 && count <= 10){
            randomShipItem = gameControl.getInv().getRandomShipItem();
            count++;
        }
        if(randomShipItem.getCurrentAmount() <= 0){
            super.messageText = getDummyText();
            
        } else {
            if(gameControl.getPlayer() instanceof Engineer && rand.nextDouble() > .95){
                super.formatMessage("You lost " + randomShipItem.toString());
            } else if (!(gameControl.getPlayer() instanceof Engineer) && rand.nextDouble() > .7){
                super.formatMessage("You lost " + randomShipItem.toString());
            } else {
                super.messageText = getDummyText();
            }
        }
        
    }
    public void Action(){
        Random rand = new Random();
        if(randomShipItem.getCurrentAmount() == 1){
            randomShipItem.removeCurrentAmount(1);
            super.formatMessage("You lost 1 " + randomShipItem.toString() );
        } else {
            int randAmountRemoved = rand.nextInt(randomShipItem.getCurrentAmount() - 1) + 1;
            randomShipItem.removeCurrentAmount(randAmountRemoved);
            super.formatMessage("You lost  " + randAmountRemoved + " " + randomShipItem.toString());
        }
    }  
}
